<?php
// +----------------------------------------------------------------------
// | Description: about us
// +----------------------------------------------------------------------
// | Author: orchief
// +----------------------------------------------------------------------
// | Date: 2018-03-06 13:37:11
// +----------------------------------------------------------------------

namespace App\Model;

use App\Common\Model;

class Member extends Model
{
    protected $fuzzyConditions = ['username', 'cellPhone', 'shopUsername', 'province', 'city', 'hometown'];
    protected $clearConditions = ['id', 'roleId', 'shopId', 'cityId', 'referId', 'regionId'];
    protected $returnFields = '';
    protected $rangeConditions = null;
    protected $union_fuzzyConditions = null;
    protected $foreignConditions = null;
    protected $name = 'pudu_members';

    /**
     * 解析搜索条件
     */
    public function getDataList($param)
    {
        $this->param = $param;
        if($this->param['roleId'] == -1){
            $roleId = -1;
            unset($this->param['roleId']);
        }
        if (isset($this->param['page'])) {
            $this->page = $this->param['page'];
        }
        if (isset($this->param['limit'])) {
            $this->limit = $this->param['limit'];
        }
        if (!empty($this->param['orderByString'])) {
            $this->orderByString = $this->param['orderByString'];
        }
       
        // 数据
        $Model = $this;
        $Model = $this->parseParam($Model);
        if($roleId == -1){
            $Model = $Model->where('level', '>', 0);
        }
        $Model = $Model->field($this->returnFields);
        if ($this->limit != -1) {
            $Model = $Model->page($this->page, $this->limit);
        }
        $resData = $Model->select();
        // 数量
        $Model = $this;
        $Model = $this->parseParam($Model);
        if($roleId == -1){
            $Model = $Model->where('level', '>', 0);
        }
        $dataCount = $Model->count();
        $data['list'] = $resData;
        $data['dataCount'] = $dataCount;
        return $this->filter($data);
    }
}